package com.jnxx.task.controller;

import com.jnxx.basic.query.PageInfo;
import com.jnxx.basic.util.AjaxResult;
import com.jnxx.task.domain.Okrproject;
import com.jnxx.task.query.OkrprojectQuery;
import com.jnxx.task.service.IOkrprojectService;
import com.jnxx.task.vo.GetProgressDetailVo;
import com.jnxx.task.vo.ProjectDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/api/okrproject")
public class OkrprojectController {

    @Autowired
    public IOkrprojectService okrprojectService;

    /**
     * 接口：添加或修改
     * @param okrprojectMap  传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Map<String, Okrproject> okrprojectMap){
        Okrproject okrproject = okrprojectMap.get("project");
        if( okrproject.getId()!=null){
		    okrprojectService.update(okrproject);
        }else{
            okrprojectService.add(okrproject);
	}
        return new AjaxResult();
       
    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        okrprojectService.del(id);
        return new AjaxResult();
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        okrprojectService.batchDel(ids);
        return new AjaxResult();
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}")
    public Okrproject findOne(@PathVariable("id")Long id) {
        return okrprojectService.findOne(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<Okrproject> findAll(){
        return okrprojectService.findAll();
    }

    /**
     * 接口：根据员工id查询所有
     * @return
     */
    @GetMapping("/findAllByStaffId/{staffId}")
    public List<Okrproject> findAllByStaffId(@PathVariable("staffId") Long staffId){
        return okrprojectService.findAllByStaffId(staffId);
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public PageInfo<Okrproject> page(@RequestBody OkrprojectQuery query) {
        return okrprojectService.page(query);
    }

    /**
     * 接口：查询单个对象
     */
//    @GetMapping("/getDetaile/{projectId}/{moduleId}")
//    public ProjectDetailVo getDetaile(@PathVariable("projectId")Long projectId, @PathVariable("moduleId")Integer moduleId) {
//        return okrprojectService.getDetaile(projectId);
//    }
    @PostMapping("/getDetaile")
    public ProjectDetailVo getDetaile(@RequestBody Map<String, GetProgressDetailVo> idMap) {
        return okrprojectService.getDetaile(idMap);
    }
}
